package com.hxzy.controller;

import com.hxzy.common.RabbitMQConst;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HellowordApplication {


    /**
     * rabbit封装好的消息发送的模板类
     */
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping(value = "/hello/send")
    public String sendHelloMsg(){

        //发送消息
        this.rabbitTemplate.convertAndSend(RabbitMQConst.DEMO_QUEUE, "你好");

        return "ok";

    }


    @GetMapping(value = "/hello/send/batch")
    public String sendHelloMsgBatch(){

        for(int i=1;i<=50;i++) {
            //发送消息
            this.rabbitTemplate.convertAndSend(RabbitMQConst.DEMO_QUEUE, "你好"+i);
        }
        return "ok";

    }

}
